package com.example.servlet.notice;

import com.alibaba.fastjson.JSON;
import com.example.model.Notice;
import com.example.service.NoticeService;
import com.example.service.impl.NoticeServiceImpl;
import com.example.vo.Page;
import com.example.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 公告的分页显示
 */
@WebServlet("/noticeServlet/queryAll")
public class QueryAllServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/json;charset=utf-8");
        NoticeService noticeService = new NoticeServiceImpl();
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");
        Map<String,String> params = new HashMap<>();
        params.put("currentPage",currentPage);
        params.put("pageSize",pageSize);
        Page<Notice> page = noticeService.getPage(params);
        resp.getWriter().println(JSON.toJSONString(ResponseData.ok(page)));
    }
}
